﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Chinaer.Web
{
    public partial class Address : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Binding();
            }
        }

        private void Bind()
        {
            List<DTO.CountryDTO> listCountry = CommonService.GetChinaerService.GetAllCountry("");
            this.ddlCountry.DataSource = listCountry;
            this.ddlCountry.DataTextField = "CountryName";
            this.ddlCountry.DataValueField = "ID";
            this.ddlCountry.DataBind();

            List<DTO.ProvinceDTO> listProvince = CommonService.GetChinaerService.GetProvinceByCountryID(this.ddlCountry.SelectedValue, "");
            this.ddlProvince.DataSource = listProvince;
            this.ddlProvince.DataTextField = "Name";
            this.ddlProvince.DataValueField = "ID";
            this.ddlProvince.DataBind();

            List<DTO.CityDTO> listCity = CommonService.GetChinaerService.GetCityByProvinceID(this.ddlProvince.SelectedValue, "");
            this.ddlCity.DataSource = listCity;
            this.ddlCity.DataTextField = "CityName";
            this.ddlCity.DataValueField = "ID";
            this.ddlCity.DataBind();

        }


        protected void btnAdd_Click(object sender, EventArgs e)
        {
            var result = CommonService.GetChinaerService.AddAddress(new DTO.AddressDTO()
                {
                    Address = this.txtName.Text.Trim(),
                    CityID = this.ddlCity.SelectedValue,
                    ProvinceID = this.ddlProvince.SelectedValue,
                    CountryID = this.ddlCountry.SelectedValue,
                    CreateTime = DateTime.Now,
                    CustomerID = "11",
                    Description = "地址描述信息",
                    IsDelete = false,
                    IsUse = true
                });
            Response.Write(result);

            Binding();
        }
        private void Binding()
        {
            List<DTO.AddressDTO> listAddress = CommonService.GetChinaerService.GetAddressByCustomerID("11", "");
            this.gvList.DataSource = listAddress;
            this.gvList.DataBind();
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            Bind();
        }
    }
}